﻿@{
    ViewBag.Title = "MyScheduleList";
    Layout = "~/_Layout.cshtml";
}
<link href="~/Resource/Css/Paging.css" rel="stylesheet" />

<style type="text/css">
    .bodycontent {
        margin-left: auto;
        margin-right: auto;
    }

    .fleft {
        float: left;
        width: 23%;
        text-align: center;
        cursor: pointer;
        border: 1px solid;
        height: 25px;
        line-height: 25px;
        border-right: 0px solid;
    }

    .fleft1 {
        float: left;
        width: 23%;
        text-align: center;
        cursor: pointer;
        border: 1px solid;
        height: 25px;
        line-height: 25px;
        border-left: 1px solid;
        border-right: 0px solid;
    }

    .fleft2 {
        float: left;
        width: 23%;
        text-align: center;
        cursor: pointer;
        border: 1px solid;
        height: 25px;
        line-height: 25px;
        border-left: 1px solid;
    }

    .divp {
        width: 500px;
    }
</style>

<div class="bodycontent">
    <div style="margin-top: 8px; float: left; margin-right: 5px;"> 
        <a href="/Schedule/NewSchedule">添加</a>
    </div>
    <div class="divp" style="float:left">
        <div class="fleft" id="div1">
            未提交
        </div>
        <div class="fleft1" id="div2">
            已提交
        </div>
        <div class="fleft1" id="div3">
            已完成
        </div>
        <div class="fleft2" id="div4">
            待审核
        </div>
    </div>
    <div style="clear: both; height: auto; padding-top: 10px;">
        <table id="div_schedule" class="tab"></table>
    </div>
</div>

<div id="scheduleList_paging" class="product_result_sum" style="padding-bottom: 20px; padding-top: 5px;">
</div>

<script type="text/javascript">
    $("#div1").click(function () {
        ResetColor();
        $(this).css("background-color", "#eeeeee").css("font-weight", "bold");

        var url = '@Url.Action("GetMyUnfinishSchedules", "Schedule")'
        GetSchedulesByStatus(url, "unfinish");
    })
    $("#div2").click(function () {
        ResetColor();
        $(this).css("background-color", "#eeeeee").css("font-weight", "bold");

        var url = '@Url.Action("GetMyPeddingSchedules", "Schedule")'
        GetSchedulesByStatus(url, "pedding");
    })
    $("#div3").click(function () {
        ResetColor();
        $(this).css("background-color", "#eeeeee").css("font-weight", "bold");

        var url = '@Url.Action("GetMyFinishSchedules", "Schedule")'
        GetSchedulesByStatus(url, "finish");
    })
    $("#div4").click(function () {
        ResetColor();
        $(this).css("background-color", "#eeeeee").css("font-weight", "bold");

        var url = '@Url.Action("GetMyApprovechedules", "Schedule")'
        GetSchedulesByStatus(url, "approve");
    })

    function ResetColor() {
        $("#div1").css("background-color", "white").css("font-weight", "normal");
        $("#div2").css("background-color", "white").css("font-weight", "normal");
        $("#div3").css("background-color", "white").css("font-weight", "normal");
        $("#div4").css("background-color", "white").css("font-weight", "normal");
    }

    function GetSchedulesByStatus(url, tag) {
        SendAjax("get", url, { ran: Math.random, tag: "GetMyUnfinishSchedules" }, "json", function (data) {
            data = data.Data;
            //如果没数据 就清空
            if (data == null || data.length == 0) {

                $("#div_schedule tr").each(function () {
                    $(this).remove();
                })
                $("#scheduleList_paging").html("");
                return;
            }
            $("#scheduleList_paging").html("");
            var _res = new pagingMgr(data, 5, RenderUnfinishData, "scheduleList_paging");
            _res.GetResult();
            _res.RenderPaging($("#scheduleList_paging"));
            RenderUnfinishData(_res._result[0], tag);
        });
    }

    function RenderUnfinishData(data, tag) {

        $("#div_schedule tr").each(function () {
            $(this).remove();
        })

        var html = "";
        html += "<tr>";
        html += "<td>标题</td>";
        html += "<td>内容</td>";
        html += "<td>发送人</td>";
        html += "<td>开始日期</td>";
        html += "<td style='width:190px;'>审批人</td>";
        html += "<td>操作</td>";
        html += "</tr>";
        for (var i = 0; i < data.length; i++) {
            html += "<tr>";
            html += "<td>" + data[i].Title + "</td>";
            html += "<td title='" + data[i].Contents + "'>" + cutStr(data[i].Contents, 10) + "</td>";
            html += "<td>" + data[i].SendUid + "</td>";
            html += "<td>" + data[i].BeginDate + "</td>";
            html += "<td>" + data[i].ApproveUid + "</td>";
            if (tag == "unfinish") {
                html += "<td><a tag='Edit' EditId='" + data[i].Id + "' href='javascript:void(0);'>编辑</a>   <a tag='submit' submitId='" + data[i].Id + "' href='javascript:void(0);'>提交</a></td>";
            }
            if (tag == "pedding") {
                html += "<td><a tag='pedding' PeddingId='" + data[i].Id + "' href='javascript:void(0);'>查看</a></td>";
            }
            if (tag == "finish") {
                html += "<td><a tag='finish' FinishId='" + data[i].Id + "' href='javascript:void(0);'>查看</a></td>";
            }
            if (tag == "approve") {
                html += "<td><a tag='approve' ApproveId='" + data[i].Id + "' href='javascript:void(0);'>审核</a></td>";
            }
            html += "</tr>";
        }
        $("#div_schedule").append($(html));

        $("#div_schedule a[tag=Edit]").each(function () {
            this.addEventListener("click", function () { editSchedule(this); }, false);
        });

        $("#div_schedule a[tag=submit]").each(function () {
            this.addEventListener("click", function () { submitSchedule(this); }, false);
        });

        $("#div_schedule a[tag=pedding]").each(function () {
            this.addEventListener("click", function () { peddingSchedule(this); }, false);
        });

        $("#div_schedule a[tag=finish]").each(function () {
            this.addEventListener("click", function () { finishSchedule(this); }, false);
        });

        $("#div_schedule a[tag=approve]").each(function () {
            this.addEventListener("click", function () { approveSchedule(this); }, false);
        });
    }

    function editSchedule(obj) {
        var url = '@Url.Action("EditMySchedule", "Schedule")'
        url = url + "?tag=edit&id=" + $(obj).attr("EditId") + "";
        window.location.href = url;
    }

    function submitSchedule(obj) {
        var url = '@Url.Action("EditMySchedule", "Schedule")'
        url = url + "?tag=submit&id=" + $(obj).attr("submitId") + "";
        window.location.href = url;
    }

    function peddingSchedule(obj) {
        var url = '@Url.Action("MyScheduleInfo", "Schedule")'
        url = url + "?tag=pedding&id=" + $(obj).attr("PeddingId") + "";
        window.location.href = url;
    }

    function finishSchedule(obj) {
        var url = '@Url.Action("MyScheduleInfo", "Schedule")'
        url = url + "?tag=finish&id=" + $(obj).attr("FinishId") + "";
        window.location.href = url;
    }

    function approveSchedule(obj) {
        var url = '@Url.Action("ApproveSchedule", "Schedule")'
        url = url + "?tag=approve&id=" + $(obj).attr("ApproveId") + "";
        window.location.href = url;
    }

    //init
    var url = '@Url.Action("GetMyUnfinishSchedules", "Schedule")'
    GetSchedulesByStatus(url, "unfinish");
</script>
